#include<stdio.h>

int MaxSubseqSum(int List[], int N)
{
    int i, ThisSum=0, MaxSum=0;
    for (i = 0; i < N; i++) {
        ThisSum += List[i];
        if (ThisSum > MaxSum)
            MaxSum = ThisSum;
        else if (ThisSum < 0)
            ThisSum = 0;
    }
    return MaxSum;
}

int main()
{
    int N;
    scanf("%d", &N);
    int List[N];
    int i;
    for (i = 0; i < N; i++)
        scanf("%d", &List[i]);
    int maxsum;
    maxsum = MaxSubseqSum(List, N);
    printf("%d\n", maxsum);
}
